<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<br/>
<!--<div style="float: right; margin-bottom: 5px" class="box-title ">-->
    <!--<form class="form-inline" action="{:url('index/purchase/purchasedetail')}" method="get">-->
        <!--<input type="text" name="ordernumber" value="<?php if(isset($ordernumber)) echo $ordernumber ?>" class="form-control" id="exampleInputEmail3" >-->
        <!--<input type="submit" class="btn btn-default" value="搜索"/>-->
        <!--<input type="button" onclick="res({$ordernumber})" value="全部显示" class="btn btn-default"/>-->
    <!--</form>-->
<!--</div>-->
<table class="table table-bordered" style="width: 100%;margin: 0 auto">
    <tr>
        <!--<th>编号</th>-->
        <th>产品名称</th>
        <th>商家联系人</th>
        <th>进价(元)</th>
        <th>售价(元)</th>
        <th>总价(元)</th>
        <th>实际总价(元)</th>
        <th>购买数量(个)</th>
        <th>订单号</th>
        <th>快递</th>
        <th>单号</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    {foreach $result as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <!--<td>{$val.id}</td>-->
        <td style="width: 200px">{$val.pname}</td>
        <td>{$val.linkman}</td>
        <td>{$val.purchaseprice}</td>
        <td>{$val.retailprice}</td>
        <td>{$val.total}</td>
        <td>{$val.actualtotal}</td>
        <td>{$val.number}</td>
        <td>{$val.ordernumber}</td>
        <td>{$val.express}</td>
        <td>{$val.oddnumber}</td>
        <td>{if $val.status == 1} 购买申请中 {elseif $val.status == 2 /} 购买通过  {elseif $val.status == 3 /} 邮寄中 {elseif $val.status == 4 /}货已到 {elseif $val.status==5/} 已完成 {/if}</td>
        <td>
            <button onclick="del({$val.id})" type="button" class="btn btn-danger btn-xs">删除</button>
            <button onclick="details({$val.id})" type="button" class="btn btn-primary btn-xs" >详情</button>
            {if $val.status == 1}
                <button onclick="updatestatus({$val.id},this)" type="button" id='t' class="btn btn-warning btn-xs" >通过</button>
            {elseif $val.status ==2 /}
                <button onclick="order({$val.bid},{$val.ordernumber})" type="button" class="btn btn-warning btn-xs" >打款</button>
            {elseif $val.status ==3 /}
                <button onclick="cargo({$val.id})" type="button" id='y' class="btn btn-warning btn-xs" >已到</button>
            {elseif $val.status ==4 /}
                <button onclick="updatestatus({$val.id},this)" type="button" id='w' class="btn btn-warning btn-xs">完成</button>
            {else /}
                <button type="button" disabled class="btn btn-warning btn-xs " >以完成</button>
            {/if}
            <button onclick="total({$val.id})" type="button" class="btn btn-info btn-xs">添加实际总价</button>
            <button type="button" onclick="express({$val.id})" class="btn btn-default btn-xs">添加物流信息</button>
            <!--<button type="button" onclick="number({$val.id})" class="btn btn-link btn-xs" >添加单号</button>-->
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$result->render()}</div>
</div>
</body>
<script>
    //货已到
    function cargo(id) {
        $.ajax({
            url:"{:url('index/purchase/cargo')}",
            data:"id="+id,
            type:"post",
            dataType:"json",
            success:function (data) {
                if(data.success){
                    layer.alert(data.success,{bnt:['确定','取消']},
                        function () {
                            window.location.reload();
                        },function () {
                            window.location.reload();
                        }
                    );
                }
                if(data.error){
                    layer.alert(data.error);
                }
            }
        });
    }
    //修改状态
    function updatestatus(id,ts) {
        var status = ts.id;
        $.ajax({
            url:"{:url('index/purchase/updatestatus')}",
            data:"id="+id+"&status="+status,
            type:"post",
            dataType:"json",
            success:function (data) {
                if(data.success){
                    layer.alert(data.success,{bnt:['确定','取消']},
                        function () {
                            window.location.reload();
                        },function () {
                            window.location.reload();
                        }
                    );
                }
                if(data.error){
                    layer.alert(data.error);
                }
            }
        });
    }
    //打款
    function order(bid,ordernumber) {
        window.location.href = "{:url('index/settlement/detail')}?bid="+bid+"&ordernumber="+ordernumber;
    }
    //订单详情
    function details(id) {
        window.location.href = "{:url('index/purchase/Detail')}?id="+id;
    }
    //实际总价
    function total(id) {
        layer.prompt({title: '实际价格', formType: 2},
            function(total){
                $.ajax({
                    url:"{:url('/index/purchase/total')}",
                    type:"post",
                    data: "id="+id+"&total="+total,
                    dataType:"json",
                    success:function(data){
                        if(data.success){
                            layer.alert(data.success,{btn:['确定','取消']},function () {
                                window.location.reload();
                            },function () {
                                window.location.reload();
                            });
                        }else{
                            layer.alert(data.error);
                        }
                    },
                });
            }
        );
    }
    //删除
    function del(id) {
        layer.confirm('你确定要删除吗',{bnt:['确定','取消']},
            function () {
                $.ajax({
                    url:"{:url('index/purchase/delete')}",
                    type:"post",
                    data:"id="+id,
                    dataType:"json",
                    success:function (data) {
                        if(data.success){
                            layer.alert(data.success);
                            $("#del"+id).remove();
                        }
                        if(data.error){
                            layer.alert(data.error);
                        }
                    }
                });
            }
        );
    }
    //添加单号
    function number(id) {
        layer.prompt({title: '请填写运单号', formType: 2},
            function (number) {
                if(!number){
                    layer.alert('请填写运单号');
                    return;
                }
                $.ajax({
                    url:"{:url('index/purchase/number')}",
                    data:"id="+id+"&number="+number,
                    type:"post",
                    dataType:"json",
                    success:function (res) {
                        if(res.success){
                            layer.alert(res.success,{bnt:['确定']},function () {
                                location.reload();
                            });
                        }
                        if(res.error){
                            layer.alert(res.error);
                        }
                    }
                });
            }
        );
    }
    //添加物流信息
    function express(id) {
        layer.open({
            type:2,
            title:"添加物流信息",
            anim:2,
            area: ['500px', '450px'],
            content:"{:url('index/purchase/express')}?id="+id
        });
    }
    //全部显示
    function res(orderumber) {
        window.location.href = "{:url('index/purchase/purchasedetail')}?ordernumber="+orderumber;
    }
</script>
</html>